package com.sgq.vue.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.sgq.vue.dao.resource.CityMapper;
import com.sgq.vue.entity.resource.City;
import org.springframework.beans.BeanUtils;

import java.util.Map;

public class ExcelListener<S> extends AnalysisEventListener<S> {

    private CityMapper cityMapper;

    public ExcelListener(CityMapper cityMapper) {

        this.cityMapper = cityMapper;
    }

    @Override
    public void invoke(Object data, AnalysisContext context) {
        City city = new City();
        BeanUtils.copyProperties(data,city);
        cityMapper.insert(city);
    }

    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        System.out.println(headMap);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        System.out.println("执行完毕!");
    }
}